<style>
	body{
		background: #f5f5f5;
	}
	.input1{
		text-align: right;
	}
	.f1 img{
		width: 11rem;
		height: 11rem;
	}
</style>
<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">添加收款方式</p>
</div>
<div class="kong1"></div>
<div class="qq_section1">
<!--	微信-->
	{if $pay_type==1}
	<div class="qq_section1_1 anq_section2">
		<p class="pt">微信收款信息</p>
		<div class="f1 clearfix">
			<p class="p1">微信号</p>
			<p class="p2">
				<input type="text" class="input1" placeholder="请输入微信号" autocomplete="off" name='alipay2' value="{$userinfo.selfqq}">
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">收款人姓名</p>
			<p class="p2">
				<input type="text" class="input1"placeholder="微信用户名/姓名" autocomplete="off" name='username2' value="{$userinfo.selfqqname}">
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">收款二维码</p>
			<p class="p22" style="margin-top: 30px;">
				<img id="imghead2" src="{$userinfo.selfqqcode|default='__PUBLIC__/home/images/b1.png'}" alt="" {if $status.wechat eq 0} class="img_btn" {/if} data-id='2'>
				<input type="file" id="file2" data-id="2" onchange="imgChange(this);" style="height: 0px;width: 0px;" />
			</p>
		</div>
		{if $status.wechat eq 0}
		<div class="f1 clearfix">
			<p class="p1">交易密码</p>
			<p class="p2">
				<input type="text" class="input1"placeholder="交易密码" autocomplete="off"  name='pwd2'>
			</p>
		</div>
		{/if}
	</div>
	{if $status.wechat eq 0}
	<div class="qq_section1_1">
		<div class="f3">
			<input type="hidden" id="upload_geturl2" value="{$userinfo.selfqqcode}">
			<a href="javascript:;" onclick="check_repwd_wechat()">确定</a>
		</div>
	</div>
	{/if}
	{/if}
<!--	支付宝-->
	{if $pay_type==2}
	<div class="qq_section1_1 anq_section2">
		<p class="pt">支付宝收款信息</p>
		<div class="f1 clearfix">
			<p class="p1">支付宝账号</p>
			<p class="p2">
				<input type="text" class="input1" placeholder="请输入支付宝账号" autocomplete="off" name='alipay' value="{$userinfo.email}">
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">收款人姓名</p>
			<p class="p2">
				<input type="text" class="input1"placeholder="支付宝用户名/姓名" autocomplete="off" name='username' value="{$userinfo.emailname}">
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">收款二维码</p>
			<p class="p22" style="margin-top: 30px;">
				<img id="imghead1" src="{$userinfo.emailcode|default='__PUBLIC__/home/images/b1.png'}" alt="" {if $status.ali eq 0} class="img_btn" {/if} data-id='1'>
				<input type="file" id="file1" data-id="1" onchange="imgChange(this);" style="height: 0px;width: 0px;" />
			</p>
		</div>
		{if $status.ali eq 0}
		<div class="f1 clearfix">
			<p class="p1">交易密码</p>
			<p class="p2">
				<input type="text" class="input1"placeholder="交易密码" autocomplete="off"  name='pwd'>
			</p>
		</div>
		{/if}
	</div>
	{if $status.ali eq 0}
	<div class="qq_section1_1">
		<div class="f3">
			<input type="hidden" id="upload_geturl1" value="{$userinfo.emailcode}">
			<a href="javascript:;" onclick="check_repwd_ali()">确定</a>
		</div>
	</div>
	{/if}
	{/if}
<!--	银行卡-->
	{if $pay_type==3}
	<div class="qq_section1_1 anq_section2">
		<p class="pt">银行卡收款信息</p>
		<div class="f1 clearfix">
			<p class="p1">卡片所在银行</p>
			<p class="p2">
				<select name="banktypename" id="banktypename" class="input1">
					<option value="">请选择</option>
					{volist name='catelist' id='cv'}
					<option value='{$cv.bank_name}' {if condition="$cv['bank_name'] eq $userinfo['banktypename']"} selected='selected' {/if} >{$cv.bank_name}</option>
					{/volist}
				</select>
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">卡片所在支行</p>
			<p class="p2">
				<input type="text" class="input1" placeholder="开户支行" autocomplete="off" name='bankname' value="{$userinfo.bankname}">
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">银行卡账号</p>
			<p class="p2">
				<input type="text" class="input1" placeholder="银行卡号" autocomplete="off" name='bankcard' value="{$userinfo.bankcard}">
			</p>
		</div>
		<div class="f1 clearfix">
			<p class="p1">收款人</p>
			<p class="p2">
				<input type="text" class="input1" placeholder="收款人姓名" autocomplete="off" name='realname' value="{$userinfo.realname}">
			</p>
		</div>
		{if $status.bank eq 0}
		<div class="f1 clearfix">
			<p class="p1">交易密码</p>
			<p class="p2">
				<input type="text" class="input1" placeholder="交易密码" autocomplete="off"  name='pwd3'>
			</p>
		</div>
		{/if}
	</div>
	{if $status.bank eq 0}
	<div class="qq_section1_1">
		<div class="f3">
			<a href="javascript:;" onclick="check_repwd_bank()">确定</a>
		</div>
	</div>
	{/if}
	{/if}

</div>

<script>
	var is_app=0;
	try {
		is_app = android.getType();
	}catch (e) {
	}
	var site = 0;
	$(function(){
		$(".img_btn").click(function(){
			site = $(this).data("id");
			console.log(site);
			if(is_app==1){
				android.uploadImage(location.origin+"/home/Upload/appupimg.html");
			}else{
				$(this).siblings("input").click();
			}
		})
	})
</script>
<script type="text/javascript">
	//安卓回调
	function setImage(img_url) {
		$("#imghead"+site).attr('src',img_url); // 修改img标签src属性值
		$("#upload_geturl"+site).val(img_url);
	}
	function imgChange(obj) {
		var docObj=$(obj).get(0);
		if (docObj.files && docObj.files[0]) {
			if(!/image\/\w+/.test(docObj.files[0].type)){
				//图片文件的type值为image/png或image/jpg
				layer.msg("文件必须为图片！");
				return false;
			}
			var formData = new FormData();
			formData.append("files",docObj.files[0]);
			$.ajax({
				url: "{:url('Upload/upimg')}",
				type: "POST",
				data: formData,
				/**
				 *必须false才会自动加上正确的Content-Type
				 */
				contentType: false,
				/**
				 * 必须false才会避开jQuery对 formdata 的默认处理
				 * XMLHttpRequest会对 formdata 进行正确的处理
				 */
				processData: false,
				success: function (rs) {
					rs = JSON.parse(rs);
					if(rs.status==0){
						setImage(rs.data)
					}else{
						layer.alert(rs.info,{shade:0.2});return false;
					}
				},
				error: function () {
					layer.msg('系统错误，请稍后重试');
				}
			});
		} else {
			layer.msg('请上传图片');
		}
		return true;
	}
	/*开始检测交易密码和各个选项是否填写 支付宝交易填写 */
	function check_repwd_ali(){
		var name= $('input[name=username]').val();
		var user= $('input[name=alipay]').val();
		var repwd  = $('input[name=pwd]').val();
		if(name==''){
			layer.alert('请填写支付宝昵称或姓名！');return false;
		}
		if(user==''){
			layer.alert('请填写支付宝账号！');return false;
		}

		if(repwd==''){
			layer.alert('请填写交易密码！');return false;
		}
		/*ajax检测交易密码*/
		$.ajax({
			type: 'POST',
			url: "{:url('Paytype/check_repwd')}",
			dataType: "html",
			data: "code="+repwd,
			success:function(responsestr){
				if(responsestr==1){
					var img_url=$('#upload_geturl1').val();
					if(img_url==''){
						layer.alert('请上传支付宝收款码！');return false;
					}
					$.ajax({
						type: 'POST',
						url: "{:url('Paytype/doalipay')}",
						dataType: "json",
						data: {username:name,alipay:user,upload_geturl:img_url},
						success:function(re){
							var obj=re;
							if(obj.s==1){
								layer.msg(obj.msg,{shade:0.6,time:1000,end:function(){
										window.location.href=window.location.href;
									}});
							}else{
								layer.alert(obj.msg,{shade:0.2});return false;
							}
						},
						error:function(){
							layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
						}
					});
				}else{
					layer.alert(responsestr,{shade:0.2});
				}
			},
			error:function(){
				layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
			}
		});
	}

	/*开始检测交易密码和各个选项是否填写 微信交易*/
	function check_repwd_wechat(){
		var name= $('input[name=username2]').val();
		var user= $('input[name=alipay2]').val();

		var repwd  = $('input[name=pwd2]').val();
		if(name==''){
			layer.alert('请填写微信昵称或姓名！');return false;
		}
		if(user==''){
			layer.alert('请填写微信号！');return false;
		}

		if(repwd==''){
			layer.alert('请填写交易密码！');return false;
		}
		/*ajax检测交易密码*/
		$.ajax({
			type: 'POST',
			url: "{:url('Paytype/check_repwd')}",
			dataType: "html",
			data: "code="+repwd,
			success:function(responsestr){
				if(responsestr==1){
					var img_url=$('#upload_geturl2').val();
					if(img_url==''){
						layer.alert('请上传微信收款码！');return false;
					}
					$.ajax({
						type: 'POST',
						url: "{:url('Paytype/doawechat')}",
						dataType: "json",
						data: {selfqqname:name,selfqq:user,upload_geturl:img_url},
						success:function(re){
							var obj=re;
							if(obj.s==1){
								layer.msg(obj.msg,{shade:0.6,time:1000,end:function(){
										window.location.href=window.location.href;
									}});
							}else{
								layer.alert(obj.msg,{shade:0.2});return false;
							}
						},
						error:function(){
							layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
						}
					});
				}else{
					layer.alert(responsestr,{shade:0.2});
				}
			},
			error:function(){
				layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
			}
		});
	}
	function check_repwd_bank(){
		var name= $('input[name=realname]').val();
		var user= $('#banktypename').val();
		var files = $('input[name=bankname]').val();
		var img_url=$('input[name=bankcard]').val();
		var repwd  = $('input[name=pwd3]').val();
		if(name==''){
			layer.alert('请输入开户名！');return false;
		}
		var nameReg = /^[\u4E00-\u9FA5]{2,4}$/;
		if(!nameReg.test(name)){
			layer.alert('开户姓名格式错误，请检查！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
		}
		if(user==''){
			layer.alert('请选择开户行！');return false;
		}
		if(files==''){
			layer.alert('请填写开户支行！');return false;
		}
		if(repwd==''){
			layer.alert('请填写交易密码！');return false;
		}
		var cardcodepartten = /^(\d{16}|\d{17}|\d{18}|\d{19})$/;
		if(!cardcodepartten.test(img_url)){
			layer.alert('银行卡号格式错误，请检查！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
		}
		if(img_url==''){
			layer.alert('请填写银行卡号！');return false;
		}
		/*ajax检测交易密码*/
		$.ajax({
			type: 'POST',
			url: "{:url('Paytype/check_repwd')}",
			dataType: "html",
			data: "code="+repwd,
			success:function(responsestr){
				if(responsestr==1){
					$.ajax({
						type: 'POST',
						url: "{:url('Paytype/docard')}",
						dataType: "json",
						data: {realname:name,banktypename:user,bankname:files,bankcard:img_url},
						success:function(re){
							var obj=re;
							if(obj.s==1){
								layer.msg(obj.msg,{shade:0.6,time:1000,end:function(){
										window.location.href=window.location.href;
									}});
							}else{
								layer.alert(obj.msg,{shade:0.2});return false;
							}
						},
						error:function(){
							layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
						}
					});
				}else{
					layer.alert(responsestr,{shade:0.2});
				}
			},
			error:function(){
				layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
			}
		});
	}
</script>